﻿
Imports System.Collections.Generic
Public Class BanDAO
    'phuong thuc lay danh sach dua vao ma ban
    Public Shared Function LayDanhSachByMaKV(ByVal maKhuVuc As Integer) As List(Of CBan)
        Dim kq As List(Of CBan) = New List(Of CBan)
        Dim str As String = String.Format("SELECT * FROM Ban where MaKV={0}", maKhuVuc)

        Dim dt As DataTable = CKetNoi.ExecQuery(str)

        For Each i As DataRow In dt.Rows
            Dim ban As New CBan
            ban.MaBan = i("MaBan")
            ban.MaKV = i("MaKV")
            ban.TenBan = i("TenBan")
            ban.TrangThai = i("TrangThai")
            kq.Add(ban)
        Next
        Return kq
    End Function
    Public Shared Function Insert(ByVal b As CBan) As Integer
        Dim sql As String = String.Format("INSERT INTO Ban(TenBan,MaKV) VALUES('{0}',{1})", b.TenBan, b.MaKV)
        Return CKetNoi.ExecnonQuery(sql)

    End Function
    Public Shared Function Delete(ByVal maBan As Integer) As Integer
        Dim sql As String = String.Format("Delete from Ban where MaBan={0}", maBan)
        Return CKetNoi.ExecnonQuery(sql)

    End Function
    Public Shared Function Update(ByVal b As CBan) As Integer
        Dim sql As String = String.Format("Update Ban set TenBan='{0}',MaKV={1} where MaBan={2}", b.TenBan, b.MaKV, b.MaBan)
        Return CKetNoi.ExecnonQuery(sql)

    End Function
    Public Shared Function UpdateStatus(ByVal b As CBan) As Integer
        Dim sql As String = String.Format("Update Ban set TrangThai={0},where MaBan={1}", b.TrangThai, b.MaBan)
        Return CKetNoi.ExecnonQuery(sql)

    End Function
End Class
